﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using CQIE.TES.IService;
using Newtonsoft.Json.Linq;

namespace CQIE.TES.WEB.ADMIN.Controllers.Question
{
    public class QuestionAPIController : ApiController
    {
        public IQuestionService QuestionService { get; set; }
        public IEvaluaHeightService EvaluaHeightService { get; set; }

        [HttpPost]
        [Route("api/question/saveheight")]
        public object SaveHeight([FromBody]JObject model)
        {
            if (EvaluaHeightService.HaveEvaing())
            {
                // 有评教存在 无法修改
                return new
                {
                    isSuccess = false,
                    msg = "有评教正在进行中，为了公正无法修改比重！"
                };
            }

            int mode = model.Value<int>("model");
            List<int> questionlist = model.Value<JArray>("questions").ToObject<List<int>>();
            List<int> heightList = model.Values<int>("height").ToList();

            bool success = QuestionService.ChangeHeight(mode, questionlist, heightList);
            return new
            {
                isSuccess = true,
                msg = "修改成功"
            };
        }
    }
}
